package com.zhanghe.study.springcloud2.controller;

import com.zhanghe.study.model.Dept;
import com.zhanghe.study.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zh
 * @date 2021/8/19 12:25
 */
@RestController
public class DeptController {

    @Autowired
    private DeptService deptService;
//    @Autowired
//    private DiscoveryClient client;

    @RequestMapping(value = "/dept/add", method = RequestMethod.POST)
    public boolean add(@RequestBody Dept dept) {
        return deptService.add(dept);
    }

    @RequestMapping(value = "/dept/get/{id}", method = RequestMethod.GET)
    public Dept get(@PathVariable("id") Long id) {
        return deptService.get(id);
    }

    @RequestMapping(value = "/dept/list", method = RequestMethod.GET)
    public List<Dept> list() {
        return deptService.list();
    }


    //	@Autowired
//	private DiscoveryClient client;
//    @RequestMapping(value = "/dept/discovery", method = RequestMethod.GET)
//    public Object discovery()
//    {
//        List<String> list = client.getServices();
//        System.out.println("**********" + list);
//
//        List<ServiceInstance> srvList = client.getInstances("MICROSERVICECLOUD-DEPT");
//        for (ServiceInstance element : srvList) {
//            System.out.println(element.getServiceId() + "\t" + element.getHost() + "\t" + element.getPort() + "\t"
//                    + element.getUri());
//        }
//        return this.client;
//    }
}
